﻿Public Class XLChamCong
    Private kn As KNChamCong
    Public Function BUS_LoadData() As DataTable
        kn = New KNChamCong
        Return kn.DataC
    End Function

    Public Function BUS_SaveData(ByVal data As DataTable, ByVal str As String) As Boolean
        kn = New KNChamCong
        Return kn.SaveCC(data)
    End Function
    Public Sub BUS_LamMoi(ByRef data_ As DataTable, ByVal dsnv As ArrayList, ByVal thang As String)
        kn = New KNChamCong
        Dim data As New DataTable
        Dim kncc As New KNChamCong
        Dim MThang As String = "MT0"
        If data.Rows.Count <> 0 Then
            data_ = kncc.DKDSL(thang)
            For Each nv As DTO_NhanVienCT.NhanVien In dsnv
                Dim ss As Boolean = False
                For Each d As DataRow In data.Rows
                    If d("MaNV") = nv.MaNV Then
                        ss = True
                        Exit For
                    End If
                Next
                If ss = False Then
                    Dim dr As DataRow = data.NewRow
                    dr("MThang") = MThang
                    nv.MThang = MThang
                    data.Rows.Add(dr)
                    dr = data_.NewRow
                    nv.MThang = MThang
                    dr("MThang") = MThang
                    dr("Day 1") = False
                    dr("Day 2") = False
                    dr("Day 3") = False
                    dr("Day 4") = False
                    dr("Day 5") = False
                    dr("Day 6") = False
                    dr("Day 7") = False
                    dr("Day 8") = False
                    dr("Day 9") = False
                    dr("Day 10") = False
                    dr("Day 11") = False
                    dr("Day 12") = False
                    dr("Day 13") = False
                    dr("Day 14") = False
                    dr("Day 15") = False
                    dr("Day 16") = False
                    dr("Day 17") = False
                    dr("Day 18") = False
                    dr("Day 19") = False
                    dr("Day 20") = False
                    dr("Day 21") = False
                    dr("Day 22") = False
                    dr("Day 23") = False
                    dr("Day 24") = False
                    dr("Day 25") = False
                    dr("Day 26") = False
                    dr("Day 27") = False
                    dr("Day 28") = False
                    dr("Day 29") = False
                    dr("Day 30") = False
                    dr("Day 31") = False
                    data_.Rows.Add(dr)
                    BUS_MMT(MThang)
                End If
            Next

        Else
            data = kncc.DataCTThang(thang)
            For Each nv As DTO_NhanVienCT.NhanVien In dsnv
                Dim dr As DataRow = data.NewRow
                dr("Thang") = thang
                dr("MaNV") = nv.MaNV
                dr("MThang") = MThang
                data.Rows.Add(dr)
                dr = data_.NewRow
                nv.MThang = MThang
                dr("MThang") = MThang
                dr("Day 1") = False
                dr("Day 2") = False
                dr("Day 3") = False
                dr("Day 4") = False
                dr("Day 5") = False
                dr("Day 6") = False
                dr("Day 7") = False
                dr("Day 8") = False
                dr("Day 9") = False
                dr("Day 10") = False
                dr("Day 11") = False
                dr("Day 12") = False
                dr("Day 13") = False
                dr("Day 14") = False
                dr("Day 15") = False
                dr("Day 16") = False
                dr("Day 17") = False
                dr("Day 18") = False
                dr("Day 19") = False
                dr("Day 20") = False
                dr("Day 21") = False
                dr("Day 22") = False
                dr("Day 23") = False
                dr("Day 24") = False
                dr("Day 25") = False
                dr("Day 26") = False
                dr("Day 27") = False
                dr("Day 28") = False
                dr("Day 29") = False
                dr("Day 30") = False
                dr("Day 31") = False
                data_.Rows.Add(dr)
                BUS_MMT(MThang)
            Next
        End If
        Dim k As New KNLuongNV
        k.SaveCTiet(data)
        kn.SaveCC(data_)
    End Sub

    Public Sub BUS_MMT(ByRef n As String)
        Dim a As String = n.Substring(0, 2)
        Dim b As Integer = Convert.ToUInt32(n.Substring(2).ToString) + 1
        n = a & b
    End Sub

    Public Sub BUS_Dem(ByVal MaNv As String, ByRef NgNghi As Integer, ByRef NgLam As Integer, ByVal thang As String)
        kn = New KNChamCong
        Dim data As New DataTable
        Dim dataCT As New DataTable
        data = kn.DataTinh(thang)
        dataCT = kn.DataCTThang(thang)
        For Each dr As DataRow In dataCT.Rows
            If MaNv = dr("MaNV") Then
                'Dim n As Integer = 0
                'Dim l As Integer = 0
                For Each dr1 As DataRow In data.Rows
                    If dr("MThang") = dr1("MThang") Then
                        If dr1("Day 1") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 2") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 3") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 4") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 5") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 6") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 7") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 8") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 9") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 10") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 11") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 12") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 13") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 14") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 15") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 16") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 17") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 18") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 19") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 20") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 21") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 22") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 23") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 24") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 25") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 26") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 27") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 28") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 29") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 30") = False Then NgNghi += 1 Else NgLam += 1
                        If dr1("Day 31") = False Then NgNghi += 1 Else NgLam += 1
                        Exit For
                    End If
                Next
                Exit For
            End If
        Next

    End Sub
    'tim bang ctthang co mthang=mthang in thangcong

End Class
